using System;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Diagnostics;
using Cyberwolf.Modules.PWCAPAdmin.Components;
using Cyberwolf.Modules.PWCAPAdmin.UserControls;
using DotNetNuke.Common;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Skins;
using DotNetNuke.UI.Skins.Controls;

namespace Cyberwolf.Modules.PWCAPAdmin
{
    public partial class Default : PWCAPAdminBaseClass
    {
        #region Private Variables
        #endregion

        #region Public Properties
        public override MainMenu Menu
        {
            get { return pwMenu; }
        }
        #endregion

        #region Event Handlers
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {   
                if (!IsPostBack)
                {
                    // Check settings
                    if (!Utilities.SettingsOK(Settings))
                    {
                        pnPWCAPAdminContainer.Visible = false;
                        Skin.AddModuleMessage(this, Localization.GetString("SettingsError", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }

                    SetupUI();
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            // NoticeFlash
            if (NoticeFlash != null)
            {
                litNoticeFlash.Text = "<div class='fnotice'>" + NoticeFlash + "</div>";
                NoticeFlash = null;
            }

            // ErrorFlash
            if (ErrorFlash != null)
            {
                litErrorFlash.Text = "<div class='ferror'>" + ErrorFlash + "</div>";
                ErrorFlash = null;
            }

            if (DotNetNuke.Framework.AJAX.IsInstalled())
            {
                DotNetNuke.Framework.AJAX.RegisterScriptManager();
            }

            if (!DotNetNuke.UI.Utilities.ClientAPI.IsClientScriptBlockRegistered(Page, "main.js"))
            {
                DotNetNuke.UI.Utilities.ClientAPI.RegisterClientScriptBlock(Page, "main.js", "<script src=\"" + ResolveUrl("js/main.js") + "\" type=\"text/javascript\"></script>");
            }
        }
        #endregion

        #region Private Methods
        private void SetupUI()
        {
            litTitle.Text = "";

            // Menu Localization
            string sharedResourceFile = Localization.GetResourceFile(this, "PWCAPAdminShared");

            lnkLogout.Text = Localization.GetString("Logout.Text", sharedResourceFile);

            // Menu Urls

            // Menu Visibility
        }
        #endregion
    }
}